<template>
  <div>
    <el-dialog
      :title="
        addOrUpd == 2
          ? '详情'
          : addOrUpd == 1
          ? '新增'
          : addOrUpd == 3
          ? '修改'
          : '修改'
      "
      :visible.sync="dialogFlag"
      :before-close="handleClose"
      width="35%"
    >
      <el-form
        :model="dialogForm"
        label-suffix="："
        class="dialogForm"
        ref="dialogFormref"
      >
        <!-- <el-form-item label="组织架构" v-show="isShow">
                    <el-cascader :disabled="disable" size="mini" ref="cascader" v-model="option1" :options="orgTree"
                        :props="defaultProps2" @change="orgChange" clearable>
                    </el-cascader>
                </el-form-item> -->
        <el-form-item label="选择项目" v-show="isShow">
          <el-select
            :disabled="disable"
            size="mini"
            @change="changeXq"
            v-model="dialogForm.xqId"
            placeholder="请选择项目"
          >
            <el-option
              v-for="item in xqOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="收费标准名称"
          prop="name"
          :rules="{ required: true, message: '该项不能为空', trigger: 'blur' }"
        >
          <el-input :disabled="disable" size="mini" v-model="dialogForm.name" />
        </el-form-item>
        <el-form-item
          label="选择费项"
          prop="costItemId"
          :rules="{ required: true, message: '该项不能为空', trigger: 'blur' }"
        >
          <el-cascader
            size="mini"
            v-model="dialogForm.costItemId"
            :options="costItemOptions"
            :props="{
              expandTrigger: 'hover',
              label: 'name',
              checkStrictly: true,
              value: 'id',
            }"
            @change="costItemChange"
          ></el-cascader>
        </el-form-item>
        <el-form-item
          label="计算方式"
          prop="calculationMethod"
          :rules="{ required: true, message: '该项不能为空', trigger: 'blur' }"
        >
          <el-radio-group
            v-model="dialogForm.calculationMethod"
            @change="calculationMethodChange"
          >
            <el-radio :disabled="disable" :label="1">面积</el-radio>
            <el-radio :disabled="disable" :label="2">仪表读数</el-radio>
            <el-radio :disabled="disable" :label="3">单位单价</el-radio>
            <el-radio :disabled="disable" :label="4">固定金额</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="缴费类型"
          prop="calculationCycle"
          :rules="{ required: true, message: '该项不能为空', trigger: 'blur' }"
        >
          <el-radio-group
            v-model="dialogForm.calculationCycle"
            @change="calculationCycleChange"
          >
            <el-radio
              :disabled="disable"
              :label="1"
              v-if="dialogForm.calculationMethod != 2"
            >
              周期缴费</el-radio
            >
            <el-radio :disabled="disable" :label="2">单次缴费</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="仪表类型"
          prop="meterType"
          :rules="{ required: true, message: '该项不能为空', trigger: 'blur' }"
          v-if="dialogForm.calculationMethod == 2"
        >
          <el-select
            :disabled="disable"
            class="input100"
            size="mini"
            v-model="dialogForm.meterType"
            placeholder="请选择"
          >
            <el-option
              v-for="(item, index) in meterUnitList"
              :label="item.name"
              :value="item.code"
              :key="item + index"
            >
              <span style="float: left">{{ item.name }}({{ item.code }})</span>
            </el-option>
          </el-select>
        </el-form-item>
        <!-- v-if="dialogForm.calculationCycle==1&&dialogForm.calculationCycle==1" -->
        <el-form-item
          label="单价"
          class="is-required"
          
        >
          <el-input
            :disabled="disable"
            class="input100"
            size="mini"
            v-model="dialogForm.unitPrice"
          >
          </el-input>
          <span>
            元
            <span v-if="dialogForm.calculationMethod == 1"
              >&nbsp; /m² &nbsp;</span
            >
            <!-- /m² -->&nbsp;
          </span>
          <span
            v-if="
              dialogForm.calculationMethod == 3 ||
              dialogForm.calculationMethod == 2
            "
            >/</span
          >
          <!-- || (dialogForm.calculationMethod==1 && dialogForm.calculationCycle==2) -->
          <el-select
            :disabled="disable"
            v-if="
              dialogForm.calculationMethod == 3 ||
              dialogForm.calculationMethod == 2
            "
            class="input100"
            size="mini"
            v-model="dialogForm.unit"
            placeholder="数量单位"
          >
            <el-option
              v-for="item in numUnitList"
              :key="item.id"
              :label="item.name"
              :value="item.name"
            >
            </el-option>
          </el-select>
          &nbsp;

          <span
            v-if="
              dialogForm.calculationCycle == 1 ||
              (dialogForm.calculationMethod == 3 &&
                dialogForm.calculationCycle != 2) ||
              (dialogForm.calculationMethod == 4 &&
                dialogForm.calculationCycle != 2)
            "
            >/</span
          >
          <span
            v-if="
              dialogForm.calculationCycle == 1 ||
              (dialogForm.calculationMethod == 3 &&
                dialogForm.calculationCycle != 2) ||
              (dialogForm.calculationMethod == 4 &&
                dialogForm.calculationCycle != 2)
            "
            >月</span
          >
          <!-- <el-select :disabled="disable" v-if="dialogForm.calculationCycle==1
                        ||dialogForm.calculationMethod==3||dialogForm.calculationMethod==4" class="input100"
                        size="mini" v-model="dialogForm.unit" placeholder="时间单位">
                        <el-option v-for="item in timeUnitList" :key="item.id" :label="item.name" :value="item.name">
                        </el-option>
                    </el-select> -->
        </el-form-item>
        <!-- v-if="dialogForm.calculationCycle==1&&dialogForm.calculationCycle==1" -->
        <el-form-item
          label="数量"
          class="is-required"
          v-if="
            dialogForm.calculationMethod == 1 ||
            dialogForm.calculationMethod == 3 ||
            (dialogForm.calculationMethod == 4 &&
              dialogForm.calculationCycle == 1)
          "
        >
          <el-select
            size="mini"
            v-if="dialogForm.calculationMethod == 1"
            @change="areaTypeChange"
            class="input100"
            v-model="dialogForm.areaType"
            placeholder="请选择"
          >
            <el-option label="统一面积" :value="0"></el-option>
            <el-option label="建筑面积" :value="1"></el-option>
            <el-option label="使用面积" :value="2"></el-option>
            <el-option label="公摊面积" :value="3"></el-option>
          </el-select>
          <el-input
            v-if="dialogForm.areaType == 0 || dialogForm.calculationMethod != 1"
            :disabled="disable"
            size="mini"
            class="input100"
            v-model="dialogForm.num"
          />
          <span v-if="dialogForm.calculationMethod == 1">&nbsp; m² &nbsp;</span>
          <span v-if="dialogForm.calculationMethod == 3"
            >&nbsp; {{ dialogForm.unit }} &nbsp;</span
          >
          &nbsp;&nbsp;&nbsp;&nbsp;
          <!-- <span v-if="dialogForm.calculationMethod==2&&dialogForm.calculationCycle==2"> 每</span>
                    <el-select :disabled="disable" v-if="dialogForm.calculationMethod==2" class="input100"
                        size="mini" v-model="dialogForm.cycle" placeholder="时间单位">
                        <el-option v-for="item in timeUnitList" :key="item.id" :label="item.name" :value="item.name">
                        </el-option>
                    </el-select> -->
          <el-input
            class="input100"
            @keyup.native="upcheckInput(dialogForm.cycle)"
            :min="1"
            v-model.number="dialogForm.cycle"
            size="mini"
            v-if="
              (dialogForm.calculationCycle == 1 &&
                dialogForm.calculationMethod == 1) ||
              (dialogForm.calculationCycle == 1 &&
                dialogForm.calculationMethod == 3)
            "
          />
          <span
            v-if="
              (dialogForm.calculationCycle == 1 &&
                dialogForm.calculationMethod == 1) ||
              (dialogForm.calculationCycle == 1 &&
                dialogForm.calculationMethod == 3) ||
              (dialogForm.calculationMethod == 4 &&
                dialogForm.calculationCycle == 1)
            "
          >
            月</span
          >
        </el-form-item>
        <el-form-item
          label="周期"
          v-if="dialogForm.calculationCycle == 1"
          :rules="{ required: true, message: '该项不能为空', trigger: 'blur' }"
          
        >
          每
          <el-input-number
            :disabled="disable"
            class="input150"
            size="mini"
            v-model="dialogForm.executeCycle"
            @change="cycleChange"
            :min="1"
            label="描述文字"
          ></el-input-number>
          月付一次
        </el-form-item>
        <el-form-item
          label="生效时间"
          :rules="{ required: true, message: '该项不能为空', trigger: 'blur' }"
        >
          <el-date-picker
            :disabled="disable"
            size="mini"
            v-model="dialogForm.validityStart"
            value-format="timestamp"
            type="datetime"
            placeholder="选择日期时间"
          >
          </el-date-picker>
          ——
          <el-date-picker
            :disabled="disable"
            size="mini"
            v-model="dialogForm.validityEnd"
            value-format="timestamp"
            type="datetime"
            placeholder="选择日期时间"
          >
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="是否银行划账" :rules="{required: true, message: '该项不能为空', trigger: 'blur'}">
                    <el-radio :disabled="disable" :label="1" v-model="dialogForm.remitAccount">是</el-radio>
                    <el-radio :disabled="disable" :label="0" v-model="dialogForm.remitAccount">否</el-radio>
                </el-form-item> -->
        <el-form-item label="备注">
          <el-input
            :disabled="disable"
            type="textarea"
            v-model="dialogForm.remark"
          ></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button
          type="primary"
          v-if="addOrUpd != 2"
          @click="addOrEditBtn(1)"
          >{{ addOrUpd == 1 ? "添 加" : "修 改" }}</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  meterconfiglist,
  getDictionary,
  getDictionaryByType,
  chargeStandardTempAdd,
  chargeStandardTempUpdate,
  orgTree,
  getCostItemList,
  xqSelectList,
  houseBindUpdate,
} from "../../url/api";
export default {
  props: ["dialogVisible", "updObj", "addOrUpd", "disable", "xqId"],
  data() {
    return {
      isShow: true,
      // disable: false,
      costItemOptions: [],
      option1: [],
      orgTree: [],
      xqOptions: [],
      dialogForm: {
        costItemId: "",
        name: "",
        xqId: "",
        orgId: "",
        calculationCycle: 1,
        calculationMethod: 1,
        remitAccount: 1,
        areaType: 0,
        unitPrice: "0", //单价
        unit: "", //单位
        cycle: "1", //计量周期
        executeCycle: "",
        num: "1",
        meterType: "",
        validityStart: "",
        validityEnd: "",
        remark: "",
      },
      defaultProps2: {
        children: "children",
        label: "name",
        value: "id",
        expandTrigger: "hover",
        checkStrictly: true,
      },
      dialogFlag: false,
      dictionaryList: [],
      dictionaryType: "",
      timeUnitList: [], //时间单位
      numUnitList: [], //数量单位
      meterUnitList: [], //仪表单位
      getOrgIds: [],
      codedata: [],
    };
  },
  watch: {
    addOrUpd(val) {
      /*
                    1 选择,2 详情,3 修改模板界面进来的

                    4 修改 房间绑定的模板
                */
      //console.log('监听判断状态：:', val);
      // if (val == 3) {
      //     this.dialogFlag = this.dialogVisible;
      //     this.dialogForm = this.updObj;
      //     //console.log(this.dialogForm);
      // } else
      if (val == 3 || val == 4) {
        //console.log('进来了，3 or 4', val);
        if (val == 4) this.isShow = false;
        // this.disable = false;
        // this.dialogForm = this.updObj;
        let data = JSON.parse(JSON.stringify(this.updObj));
        this.dataInit(data);
        this.getmeterconfiglist();
        this.$forceUpdate();

        // this.dialogForm.remitAccount = this.updObj.remitAccount ? 1 : 0;
        // this.getOrgParentId(this.orgTree, this.updObj.orgId);
        // this.getOrgIds.unshift(this.orgTree[0].id);
        // this.option1 = this.getOrgIds;
        //console.log(this.dialogForm);
      } else if (val == 1) {
        // exist_temp_manage

        this.dialogForm = {
          name: "",
          costItemId: "",
          xqId: "",
          // xqId: '',
          orgId: "",
          calculationCycle: 1,
          calculationMethod: 1,
          remitAccount: 1,
          areaType: 0,
          unitPrice: "", //单价
          unit: "", //单位
          cycle: "", //计量周期
          executeCycle: "",
          num: "",
          meterType: "",
          validityStart: "",
          validityEnd: "",
          remark: "",
          // cycle:1,
        };
        // console.log(this.$route.path);
        if (this.$route.path == "/addChargeStandardTemp") {
          this.dialogForm.xqId = this.xqId;
          this.getmeterconfiglist();
          this.changeXq(this.xqId);
        }
        this.isShow = true;
        this.option1 = [];
        this.option1 = [];
      } else if (val == 2) {
        //console.log('--------detail-------------');
        this.dialogForm = this.updObj;
        this.dialogForm.remitAccount = this.updObj.remitAccount ? 1 : 0;
        this.getOrgParentId(this.orgTree, this.updObj.orgId);
        this.getOrgIds.unshift(this.orgTree[0].id);
        this.option1 = this.getOrgIds;
      }
    },
    updObj: {
      handler(val) {
        this.dataInit(val);
      },
      immediate: true,
    },
    dialogVisible() {
      this.dialogFlag = this.dialogVisible;
    },
    // 'dialogForm.calculationMethod'(val) {
    //     if (val == 2) {
    //         this.dialogForm.calculationCycle = 2;
    //     }
    //     this.getDicType();
    // },
    // 'dialogForm.calculationCycle'() {
    //     this.getDicType();
    // },
  },
  methods: {
    clearValidate() {
      let dialogFormref = this.$refs["dialogFormref"];
      if (dialogFormref) {
        dialogFormref.clearValidate();
      }
    },
    dataInit(data) {
      this.dialogForm.name = data.name;
      this.dialogForm.costItemId = data.costItemId;
      this.dialogForm.xqId = data.xqId;
      this.dialogForm.id = data.id;
      this.dialogForm.calculationCycle = data.calculationCycle;
      this.dialogForm.calculationMethod = data.calculationMethod;
      this.dialogForm.remitAccount = data.remitAccount ? 1 : 0;
      this.dialogForm.areaType = data.areaType;
      this.dialogForm.unitPrice = "" * 1;
      this.dialogForm.unitPrice = data.unitPrice; //单价
      this.dialogForm.unit = data.unit; //单位
      this.dialogForm.cycle = data.cycle; //计量周期
      this.dialogForm.executeCycle = data.executeCycle;
      this.dialogForm.num = data.num;
      this.dialogForm.meterType = data.meterType;
      this.dialogForm.validityStart = data.validityStart;
      this.dialogForm.validityEnd = data.validityEnd;
      this.dialogForm.remark = data.remark;
    },
    areaTypeChange() {
      this.dialogForm.num = "";
    },
    calculationCycleChange() {
      this.dialogForm.areaType = 0;
      this.dialogForm.unitPrice = ""; //单价
      this.dialogForm.unit = ""; //单位
      this.dialogForm.cycle = ""; //计量周期
      this.dialogForm.executeCycle = "";
      this.dialogForm.num = "";
      this.dialogForm.meterType = "";
      this.getDicType();
    },
    calculationMethodChange(val) {
      if (val == 2) {
        this.dialogForm.calculationCycle = 2;
      }
      // this.dialogForm = {
      //         costItemId: '',
      //         orgId: '',
      //         xqId: this.xqId,
      //         calculationCycle: 1,
      //         calculationMethod: 1,
      //         remitAccount: 1,
      //         executeCycle: 1, //月付次数
      //         // cycle:1,
      //  };
      this.dialogForm.areaType = 0;
      this.dialogForm.unitPrice = ""; //单价
      this.dialogForm.unit = ""; //单位
      this.dialogForm.cycle = ""; //计量周期
      this.dialogForm.executeCycle = "";
      this.dialogForm.num = "";
      this.dialogForm.meterType = "";
      this.getDicType();
    },
    initialize() {
      this.dialogForm = {
        costItemId: "",
        name: "",
        xqId: "",
        orgId: "",
        calculationCycle: 1,
        calculationMethod: 1,
        remitAccount: 1,
        areaType: 0,
        unitPrice: "", //单价
        unit: "", //单位
        cycle: "", //计量周期
        executeCycle: "",
        num: "",
        meterType: "",
        validityStart: "",
        validityEnd: "",
        remark: "",
      };
    },
    getmeterconfiglist() {
      let params = {
        xqId: this.dialogForm.xqId,
      };
      meterconfiglist(params).then((res) => {
        if (res.data.code == 200) {
          console.log(res);
          this.codedata = JSON.parse(JSON.stringify(res.data.data));
          console.log(this.codedata);
          // this.restoreArr = JSON.parse(JSON.stringify(res.data.data));
        }
      });
    },
    upcheckInput(value) {
      console.log(value);
      this.dialogForm.executeCycle = value;
    },
    getParentId(arr, parentId) {
      //获取父id
      if (!arr.length) return;
      arr.forEach((item, index) => {
        if (item.id == parentId) {
          this.getOrgIds.unshift(item.parentId);
        }
      });
    },
    getOrgParentId(arr, id) {
      //根据组织id获取父id
      if (!arr.length) return;
      this.getOrgIds = [];
      arr.forEach((item, index) => {
        if (item.id == id) {
          this.getOrgIds.push(item.id);
          if (item.id && item.parentId) {
            this.getOrgIds.unshift(item.parentId);
            this.getParentId(arr, item.parentId);
          } else {
            return true;
          }
        } else {
          if (!item.children) return false;
          this.getOrgParentId(item.children, id);
        }
      });
    },
    costItemChange(value) {
      console.log(value);

      if (value) {
        this.dialogForm.costItemId = value[value.length - 1];
      }
    },
    cycleChange(val) {
      if (val < 1) val = 1;
      if (val > 12) val = 12;
    },
    addOrEditBtn(val = 0) {
      // this.dialogFlag = false;
      // this.$emit('dialogFlag', {
      //     dialog: this.dialogFlag,
      //     isCancel: val,
      // });
      if (val) {
        /*
                     addOrUpd

                        1 新增,2 详情, 3 修改模板界面进来的
                        4 修改 房间绑定的模板
                    */
        console.log(this.addOrUpd);
        this.$refs.dialogFormref.validate((valid) => {
          if (valid) {
            console.log(this.addOrUpd);
            if (this.dialogForm.unitPrice == "") {
              //单价
              this.$message("请填写单价");
              return;
            }
            if (
              this.dialogForm.calculationMethod == 3 ||
              this.dialogForm.calculationMethod == 2
            ) {
              if (this.dialogForm.unit == "") {
                this.$message("请填写数量单位！");
                return;
              }
            }
            if (
              this.dialogForm.calculationMethod == 1 ||
              this.dialogForm.calculationMethod == 3 ||
              (this.dialogForm.calculationMethod == 4 &&
                this.dialogForm.calculationCycle == 1)
            ) {
              if (this.dialogForm.calculationMethod == 1) {
                // console.log(this.dialogForm.areaType);
                // if (this.dialogForm.areaType == '') {
                //     this.$message('请把数量填写完整1！')
                //     return
                // }
              }
              if (
                this.dialogForm.areaType == 0 ||
                this.dialogForm.calculationMethod != 1
              ) {
                console.log(this.dialogForm.num);
                if (this.dialogForm.num == "") {
                  this.$message("请把数量填写完整！");
                  return;
                }
              }
              if (
                (this.dialogForm.calculationCycle == 1 &&
                  this.dialogForm.calculationMethod == 1) ||
                (this.dialogForm.calculationCycle == 1 &&
                  this.dialogForm.calculationMethod == 3)
              ) {
                if (this.dialogForm.cycle == "") {
                  this.$message("请把数量填写完整！");
                  return;
                }
              }
            }

            if (this.dialogForm.validityStart == "") {
              this.$message("请填写生效开始时间！");
              return;
            }
            if (this.dialogForm.validityEnd == "") {
              this.$message("请填写生效结束时间！");
              return;
            }
            if (
              this.dialogForm.validityStart - this.dialogForm.validityEnd >=0
            ) {
              this.$message("结束时间不能大于开始时间，请重新选择！");
              return;
            }
            debugger
            console.log(this.dialogForm,"AAAAAAAAAAAAAAA");
            // this.dialogForm.num |= "1";
            // this.dialogForm.cycle |= "1";
            console.log(this.dialogForm,"BBBBBBBBBB");
            if (this.addOrUpd == 1) {
              //console.log(this.dialogForm);
              chargeStandardTempAdd(this.dialogForm).then((res) => {
                if (res.data.code == 200) {
                  this.$message.success("添加成功");
                  // this.dialogForm = {
                  //     costItemId: '',
                  //     orgId: '',
                  //     calculationCycle: 1,
                  //     calculationMethod: 1,
                  //     remitAccount: 1,
                  //     // cycle: 1, //月付次数
                  // };
                  this.initialize();
                  this.$emit("operateType", true);
                }
              });
            } else if (this.addOrUpd == 3) {
              delete this.dialogForm.orgName;
              delete this.dialogForm.xqName;
              delete this.dialogForm.unitTime;
              delete this.dialogForm.fullCostItemName;
              delete this.dialogForm.creator;
              delete this.dialogForm.gmtCreate;
              chargeStandardTempUpdate(this.dialogForm).then((res) => {
                if (res.data.code == 200) {
                  this.$message.success("修改成功");
                  this.handleClose();
                  this.$emit("operateType", true);
                }
              });
            } else if (this.addOrUpd == 4) {
              console.log("AAAAAAAAAA");
              delete this.dialogForm.orgName;
              delete this.dialogForm.xqName;
              delete this.dialogForm.unitTime;
              delete this.dialogForm.fullCostItemName;
              delete this.dialogForm.creator;
              delete this.dialogForm.gmtCreate;
              delete this.dialogForm.orgId;
              delete this.dialogForm.xqId;
              delete this.dialogForm.overdueFeeCalculationMethod;
              delete this.dialogForm.overdueFeeUnit;
              delete this.dialogForm.overdueFeeUnitPrice;
              delete this.dialogForm.overdueFeeUsable;
              // delete this.dialogForm.costItemId;
              houseBindUpdate(this.dialogForm).then((res) => {
                if (res.data.code == 200) {
                  this.$message.success("修改成功");
                  this.handleClose();
                  this.$emit("operateType", true);
                }
              });
            }
          }
        });
      }
    },
    handleClose() {
      this.dialogFlag = false;
      this.$emit("dialogFlag", {
        dialog: this.dialogFlag,
        isCancel: 0,
      });
    },
    changeXq(val) {
      let obj = this.xqOptions.filter((item) => item.id == val);
      //console.log(obj);
      this.dialogForm.xqId = val;
      let params = {
        xqId: this.dialogForm.xqId,
      };
      meterconfiglist(params).then((res) => {
        if (res.data.code == 200) {
          //console.log(res);
          this.meterUnitList = JSON.parse(JSON.stringify(res.data.data));
          //console.log(this.meterUnitList);
          // this.restoreArr = JSON.parse(JSON.stringify(res.data.data));
        }
      });
      this.dialogForm.orgId = obj[0].orgId;
      //console.log(this.dialogForm);
    },
    getDicSelect(str) {
      //根据字典字段获取单位下拉框
      if (!this.dictionaryType) return;
      getDictionaryByType({
        type: this.dictionaryType,
        resource: 1,
      }).then((res) => {
        if (res.data.code == 200) {
          this[str] = res.data.data;
          //console.log(this[str]);
        }
      });
    },
    getDicType() {
      //根据 计算方式 和 缴费类型 获取字典字段
      let {
        calculationMethod: methods,
        calculationCycle: cycle,
      } = this.dialogForm;
      //console.log(this.dictionaryList, methods, cycle);
      let arr = this.dictionaryList;
      for (let i = 0; i < arr.length; i++) {
        this.dictionaryType = arr[i].type;
        //console.log(this.dictionaryType);
        let id = arr[i].id;
        let str = "";
        if (id == 1) {
          //时间单位
          str = "timeUnitList";
        } else if (id == 7) {
          //计数单位
          str = "numUnitList";
        }
        // else if (id == 14) {
        //     //仪表单位
        //     str = 'meterUnitList';
        // }
        this.getDicSelect(str);
      }
    },
    getDic() {
      //获取字典

      getDictionary({ size: 20, current: 1 }).then((res) => {
        if (res.data.code == 200) {
          this.dictionaryList = res.data.data.records;
          this.getDicType();
        }
      });
    },
    /* orgChange(value) {
                //console.log(value);
                if (value.length != 0) {
                    this.dialogForm.orgId =
                        this.$refs.cascader.getCheckedNodes()[0].data.id;
                    xqSelectList({ orgId: this.dialogForm.orgId }).then((res) => {
                        //console.log(res);
                        if (res.data.code == 200) {
                            this.xqOptions = res.data.data;
                        } else {
                            this.$message(res.data.msg);
                        }
                    });
                } else {
                    this.dialogForm.orgId = '';
                }
            }, */
    getInit() {
      let org_tree = {
        name: "",
        status: 1,
      };
      orgTree(org_tree).then((res) => {
        //console.log(res);
        if (res.data.code == 200) {
          this.orgTree = res.data.data;
        }
      });

      getCostItemList().then((res) => {
        if (res.data.code == 200) {
          this.costItemOptions = res.data.data;
        }
      });
    },
  },
  mounted() {
    // console.log("hahahhahahaha", this.houseIds);
    this.dialogFlag = this.dialogVisible;
    this.getDic();
    this.getInit();
    //console.log(this.addOrUpd);
    //
    if (!this.addOrUpd) {
      xqSelectList({ orgId: this.dialogForm.orgId }).then((res) => {
        //console.log(res);
        if (res.data.code == 200) {
          this.xqOptions = res.data.data;
          this.dialogForm.xqId = this.xqOptions[0].id;
          let params = {
            xqId: this.dialogForm.xqId,
          };
          meterconfiglist(params).then((res) => {
            if (res.data.code == 200) {
              //console.log(res);
              this.meterUnitList = JSON.parse(JSON.stringify(res.data.data));
              //console.log(this.meterUnitList);
              // this.restoreArr = JSON.parse(JSON.stringify(res.data.data));
            }
          });
          this.dialogForm.orgId = this.xqOptions[0].orgId;
        } else {
          this.$message(res.data.msg);
        }
      });
    }
  },
};
</script>

<style scoped lang='scss'>
.dialogForm /deep/ .input100 {
  width: 100px;
}
.dialogForm /deep/ .input150 {
  width: 150px;
}

.dialogForm /deep/ .input50 {
  width: 50px;
}
</style>
